package cn.bdqn.controller;

import cn.bdqn.dao.ExamMapper;
import cn.bdqn.pojo.Exam;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 刘旻昊
 * @Date: Created in 2020/6/22  19:10
 */
@org.springframework.stereotype.Controller
@RestController
public class ExamController {
    @Resource
    ExamMapper examMapper;
    @GetMapping("/list2")
    public String list(Model model){
        List<Exam> list= examMapper.listAll();
        model.addAttribute("list",list);
        return "list2";
    }

    @RequestMapping("/index2")
    public String index(Model model){
        List<Exam> list= examMapper.listAll();
        model.addAttribute("list",list);
        return "index2";
    }
    @ResponseBody
    @RequestMapping("/delete/{id}2")
    public String del(@PathVariable("id") Integer id){
        Integer i=0;
        i= examMapper.del(id);
        return i.toString();
    }

    @RequestMapping("/toadd2")
    public String add(){
        return "hello";
    }
    @RequestMapping("/add2")
    public String adds(Exam exam, Model model){
        Integer res= examMapper.insert(exam);
        if (res>0){
            List<Exam> list= examMapper.listAll();
            model.addAttribute("list",list);
            return "index2";
        }else{
            return "hello";
        }
    }

    @RequestMapping("/selectByid/{id}2")
    public String seleId(@PathVariable("id") Integer id, Model model){
        Exam list= examMapper.listAllByid(id);
        model.addAttribute("list1",list);
        return "upd";
    }

    @RequestMapping("/upduser2")
    public String upd(Exam exam, Model model){
        Integer res= examMapper.upd(exam);
        if (res>0){
            List<Exam> list= examMapper.listAll();
            model.addAttribute("list",list);
            return "index2";
        }else{
            return "upd";
        }
    }
}
